package com.cashmama.market.api.application.controller.order.repay;

import com.cashmama.market.api.application.controller.order.repay.request.RepayDetailRequest;
import com.cashmama.market.api.application.controller.order.repay.request.RepayRequest;
import com.cashmama.market.api.application.controller.order.repay.request.RepayStatusRequest;
import com.cashmama.market.api.application.controller.order.repay.response.RepayDetailVO;
import com.cashmama.market.api.application.controller.order.repay.response.RepayInfoVO;
import com.cashmama.market.api.domain.service.OrderService;
import com.cashmama.market.api.domain.vo.order.OrderStatusResponse;
import com.cashmama.market.api.domain.vo.order.repayment.RepayInfo;
import com.cashmama.market.api.domain.vo.order.repayment.RepaymentDetail;
import com.cashmama.market.api.infras.handler.ApiResponse;
import com.fqgj.common.api.annotations.ParamsValidate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @program: market-api
 * @description 还款
 * @author: frank
 * @create: 2019-12-19 21:19
 **/
@RestController
@RequestMapping("/order")
public class RepayController {

    @Autowired
    private OrderService orderService;

    /**
     * 还款
     * @param repayRequest
     * @return
     */
    @ParamsValidate
    @RequestMapping(value = "/repay/post", method = RequestMethod.POST)
    public ApiResponse repay(@RequestBody @Valid RepayRequest repayRequest) {
        RepayInfo payInfoResponseVO = orderService.repay(repayRequest.getTradeNo());
        RepayInfoVO payInfoVO = new RepayInfoVO(payInfoResponseVO.getPayInfo());
        return new ApiResponse(payInfoVO.getPayInfo());
    }

    /**
     * 查询还款状态
     */
    @ParamsValidate
    @RequestMapping(value = "/repay/query", method = RequestMethod.POST)
    public ApiResponse<OrderStatusResponse> queryRepayStatus(@RequestBody @Valid RepayStatusRequest repayStatusRequest) {
        OrderStatusResponse repaymentStatus = orderService.queryRepaymentStatus(repayStatusRequest.getBillNos());
        return new ApiResponse<>(repaymentStatus);
    }

    /**
     * 账单详情
     */
   @ParamsValidate
   @RequestMapping(value = "/repay/detail", method = RequestMethod.POST)
   public ApiResponse<RepayDetailVO> repaymentDetail(@RequestBody @Valid RepayDetailRequest repayDetailRequest) {
       RepaymentDetail repaymentDetail = orderService.repaymentDetail(repayDetailRequest.getBillNo());
        return new ApiResponse<>(new RepayDetailVO(repaymentDetail));
    }

}
